package com.zmkj.cn.sys.controller;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zmkj.cn.sys.service.ISysLoginService;
import com.zmkj.cn.sys.vo.input.SysHospitalInputVo;
import com.zmkj.cn.sys.vo.input.SysLoginWechatInputVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

/**
 * 登录接口
 * @author 伍绍宇
 * @date 2021/04/21
 */
@RestController
@Api(tags ="登录接口")
public class LoginController {

    @Resource
    ISysLoginService loginService;

    /**
     * 登录界面
     *
     */
    @PostMapping("/firstLoginWeChat")
    @ApiOperation(value = "微信登录接口", httpMethod = "POST", notes = "登录接口")
    @ApiResponses({ @ApiResponse(code = 200, message = "登录成功"),
            @ApiResponse(code = 400, message = "表明在请求 API时提供了错误信息"),
            @ApiResponse(code = 500, message = "表明 API请求时,服务器发生了错误") })
    public Object loginWx(HttpServletRequest request, @ModelAttribute SysLoginWechatInputVo loginVo){
        loginVo.setNewUserLogin(false);
        return loginService.firstLoginWeChat(request, loginVo);
    }

    /**
     * 登录界面
     *
     */
    @PostMapping("/registerHospital")
    @ApiOperation(value = "注册医院接口", httpMethod = "POST", notes = "注册医院接口")
    @ApiResponses({ @ApiResponse(code = 200, message = "注册医院接口成功"),
            @ApiResponse(code = 400, message = "表明在请求 API时提供了错误信息"),
            @ApiResponse(code = 500, message = "表明 API请求时,服务器发生了错误") })
    public Object registerHospital(@ModelAttribute @Valid SysHospitalInputVo sysHospitalInputVo){
        return loginService.registerHospital(sysHospitalInputVo);
    }
}
